/**
 * @param {number[]} nums
 * @return {number}
 */
var missingNumber = function (nums) {
	// 定义左右指针和中间点
	let left = 0, right = nums.length - 1, mid;
	while (left <= right) {
		// 右移一位等同于除以2
		mid = (left + right) >> 1;
		if (nums[mid] !== mid) {
			// 缺失的数字可能是 mid - 1，或者mid=0
			if (mid === 0 || nums[mid - 1] === mid - 1) {
				return mid;
			}
			right = mid - 1;
		} else {
			left = mid + 1;
		}
	}
	// 无效的输入
	if (left === nums.length) {
		return left;
	}
	return -1;
};